package com.zyms.service.impl;

import com.zyms.module.result.ReturnCode;
import com.zyms.module.user.User;
import com.zyms.myRunTime.MyRunTimeExcption;
import com.zyms.service.Base.BaseService;
import com.zyms.service.UserService;
import com.zyms.tools.HttpClientHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2018-1-29.
 */
@Service("userService")
public class UserServiceImpl extends BaseService implements UserService {

    @Value("${user_login_synchronization_url}")
    private  String user_login_synchronization_url;

    @Override
    public User login(User user) throws MyRunTimeExcption {

        logger.info("user_login_synchronization_url is===>>>>" + user_login_synchronization_url);
        if (user == null) {
            throw new MyRunTimeExcption(ReturnCode.USER_PHONE_IS_NULL.getCode(), ReturnCode.USER_PHONE_IS_NULL.getMsg());
        }
        if (StringUtils.isBlank(user.getPhone())) {
            throw new MyRunTimeExcption(ReturnCode.USER_PHONE_IS_NULL.getCode(), ReturnCode.USER_PHONE_IS_NULL.getMsg());
        }
        Map<String, String> map = new HashMap<>();
        map.put("phone", user.getPhone());
        try {
            String resout = HttpClientHelper.doPost(user_login_synchronization_url, map);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyRunTimeExcption(e.getMessage());
        }
        logger.info("user=============>>>>");

        return null;
    }

    @Override
    public User register(User user) throws MyRunTimeExcption {
        return null;
    }

    @Override
    public User modifyUserInfo(User user) throws MyRunTimeExcption {
        return null;
    }
}
